﻿procedure;

 // Dingo
  
  procedure DingoCreateClass_40043894_10;
  var
    SLEx: TStringList;
    DSClass, DSAtr, DSAtrGroups, RedefinedAtrsDS, AttachedMacrosDS : TAppDataSet;
  begin
    if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '101,0', '40043894,10', ftID) then
    begin
      DSClass := TAppDataSet.Create;
      try
        DSClass.SetDSParams(SourceName, rmPrimary, '902,0', dsaFullNonVisible);
        DSClass.NoMacros := true;
        DSClass.OpenEmpty;
        DSClass.Append;
        DSClass.FieldByName('ic').AsString := '40043894';
        DSClass.FieldByName('u').AsString := '10';
        DSClass.FieldByName('ic_a').AsString := '';
        DSClass.FieldByName('u_a').AsString := '';
        DSClass.FieldByName('ic_b').AsString := '';
        DSClass.FieldByName('u_b').AsString := '';
        DSClass.FieldByName('611,0').AsString := 'Druhy balení manipulačních jednotek';
        DSClass.FieldByName('2652,0').AsString := '1';
        DSClass.FieldByName('13265,0').AsString := '1';
        DSClass.FieldByName('615,0').AsString := '';
        DSClass.FieldByName('613,0').AsString := '';
        DSClass.FieldByName('614,0').AsString := '';
        if DSClass.FindField('18361668,10') <> nil then
        begin
          DSClass.FieldByName('18361668,10').AsString := '';
          DSClass.FieldByName('18361669,10').AsString := '';
          DSClass.FieldByName('18361670,10').AsString := '';
        end;
        DSClass.PostNoConfirm;
      finally
        DSClass.Free;
      end;
    end;
    //
    //Insert parent class
    SLEx := TStringList.Create;
    try
      if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '136,0', '40043895,10', ftID) then
      begin
        SLEx.Clear;
        SLEx.Add('ic_a=6867912');
        SLEx.Add('u_a=10');
        SLEx.Add('ic_b=40043894');
        SLEx.Add('u_b=10');
        SLEx.Add('ic=40043895');
        SLEx.Add('u=10');
        AppServer.InsertDBRecord(SourceName, UserLang, '136,0', false, SLEx);
      end;
    finally
      SLEx.Free;
    end;
  end;   
  
  procedure DingoCopyDBAtrValue(DataSourceID, SourceClassID, SourceAtrID, SourceRecID, DestClassID, DestAtrID, DestRecID : string);
  var
    slLang : TStringList;
    sValue : string;
    i : integer;
  begin
    slLang := TStringList.Create;
    try
      // jazyky
      StringToSL(AppServer.GetDBKeyValues(DataSourceID, rmPrimary, '194,0', Format('not ("ic" = %% and "u" = %%)', [LByID(MainLang), RByID(MainLang)])), ';', slLang);
      if slLang.Count > 0 then
        begin
          while slLang.Count > i do
            begin
              sValue := AppServer.GetDBAtrValue(DataSourceID, rmPrimary, slLang.Strings[i], SourceClassID, SourceAtrID, SourceRecID);
              if sValue <> '' then
                AppServer.SetDBAtrValue(DataSourceID, slLang.Strings[i], DestClassID, DestAtrID, DestRecID, sValue);
              
              //
              i := i + 1;
            end;
        end;
    finally
      slLang.Free;
    end;
  end;
  
  procedure DingoAppendIDToSL(IDs : string; slIDs : TStringList);
  var
    sl : TStringList;
    i : integer;
  begin
    if IDs <> '' then
      begin
        sl := TStringList.Create;
        try
          StringToSL(IDs, ';', sl);
          while sl.Count > i do
            begin
              if slIDs.IndexOf(sl.Strings[i]) < 0 then slIDs.Add(sl.Strings[i]);
              i := i + 1;
            end;
        finally
          sl.Free;
        end;
      end;
  end;
  
  procedure DingoCopyLinks(SourceID, TargetID, ClassID, TargetClassID : string; ChangeID : TMTIDFieldType);
  var
    sl, slIDs : TStringList;
    i : integer;
  begin
    sl := TStringList.Create;
    slIDs := TStringList.Create;
    try
      case
        ChangeID = ftIDA :
          StringToSL(AppServer.GetDBKeyValue(SourceName, rmPrimary, ClassID, SourceID, ftIDA, ftIDB), ';', slIDs);
        ChangeID = ftIDB :
          StringToSL(AppServer.GetDBKeyValue(SourceName, rmPrimary, ClassID, SourceID, ftIDB, ftIDA), ';', slIDs);
      end;
      while slIDs.Count > i do
        begin
          sl.Clear;
          case
            ChangeID = ftIDA :
              begin
                sl.Values['ic_a'] := LByID(TargetID);
                sl.Values['u_a'] := RByID(TargetID);
                sl.Values['ic_b'] := LByID(slIDs.Strings[i]);
                sl.Values['u_b'] := RByID(slIDs.Strings[i]);
              end;
            ChangeID = ftIDB :
              begin
                sl.Values['ic_a'] := LByID(slIDs.Strings[i]);
                sl.Values['u_a'] := RByID(slIDs.Strings[i]);
                sl.Values['ic_b'] := LByID(TargetID);
                sl.Values['u_b'] := RByID(TargetID);
              end;
          end;
          AppServer.InsertDBRecord(SourceName, '', TargetClassID, False, sl);
          i := i + 1;
        end;
    finally
      slIDs.Free;
      sl.Free;
    end;
  end;
   
  //





var
  SLDoplInfo_KaSo, SLDoplnInfoVazba_KaSo: TStringList;
  DS_KaSo: TAppDataSet;
  IDDokladu_KaSo, IDDoplnInfo_KaSo: string;
  
  DSEldp: TAppDataSet;
  idPpv, str, typePpv, mr, rc, StreetEmpl, NumEmpl, post, psc, email, phone, ActivFrom: string;
  dateRealStartPpv: DateTime;
  dpp, dpc: boolean;
  
  MP_DSNasnData: TAppDataSet;
  MP_DSParam: TAppDataSet;
  
  MP_SLExKod: TStringList;
  MP_IDStatku, MP_Kod: String;
  MP_Index: Integer;  

  DSPar, DSMS: TAppDataSet;
  SL: TStringList;
  idPer, ic, u: string;
  holidayDraw: float;
  year, month, day, i: integer;
  dateStartYear, dateStartPer: DateTime;
  
  dingo_sl, dingo_slIDs, dingo_slLang, dingo_UserIDs, dingo_SectorIDs : TStringList;
  dingo_sRemoteKey, dingo_UserName : string;
  dingo_RoleID : string;
  dingo_i : integer;
  
// var AV1
var AV1_DS: TAppDataSet;
// var AV1 - konec
  sTemp: string; //VKo
  
  LuP_SL : TStringList;
  LuP_DS, LuP_ContenctMNUDS, LuP_DocumentItems, DSEmpl: TAppDataSet;
  LuP_Filter, LuP_Prep, LuP_ID, LuP_Switch, idState: String;
  LuP_Mnoz, LuP_MnozEJ : Float;
  LuP_Index, LuP_ISwitch : Integer;

  QIG_VK_SL_ID : TStringList;
  QIG_VK_Data, QIG_VK_ID : string;
  QIG_VK_i : integer;
  
  MS_SL, MS_SLText: TStringList;
  MS_DS, MS_DSPresuny: TAppDataSet;
  MS_Node, MS_IDsPres: String;
  MS_i: integer;
  
  PM_SL : TStringList;
  PM_IDConf, PM_IDs, PM_IDState: string;
  PM_i: integer;

  //
  procedure MS_GetKontexty(IDProcesZdroj, IDProcesCil:string; SL: TStringList);
  var
    SL1,SL2:TStringList;
    IDProcesNad : string;
    j,k: integer;
  begin
    SL.Clear;
    SL1 := TStringList.Create;
    SL2 := TStringList.Create;
    try
      StringToSL(AppServer.GetDBKeyValue(SourceName,rmPrimary,'227676,10',IDProcesZdroj,ftIDA,ftID),';',SL1);
      while j < SL1.Count do
      begin
        IDProcesNad := AppServer.GetDBKeyValue(SourceName,rmPrimary,'227676,10',SL1.Strings[j],ftID,ftIDB);
        StringToSL(AppServer.GetDBLinkKeyValue(SourceName, rmPrimary, '227676,10', IDProcesCil, IDProcesNad),';',SL2);
        k := 0;
        while k < SL2.Count do
        begin
          SL.Add(SL1.Strings[j]+';'+SL2.Strings[k]);
          k := k + 1;
        end;
        j := j + 1;
      end;
    finally
      SL1.Free;
      SL2.Free;
    end;
  end;
  
  //
  procedure MS_VytvorPresun(ZdrojNadrizeny: boolean; IDContextZdroj, IDContextCil, IDNapVVZdroj, IDNapVVCil, IDTridaZdroj, IDTridaCil: string; var IDsVytvorenych: string);
  var
    ID: string;
  begin
    MS_DSPresuny.Insert;
    if ZdrojNadrizeny then
      MS_DSPresuny.FieldByName('39894510,10').AsString := '1';
    if IDContextZdroj <> '' then
    begin
      MS_DSPresuny.FieldByName('39894480,10.ic_a').AsString := LByID(IDContextZdroj);
      MS_DSPresuny.FieldByName('39894480,10.u_a').AsString := RbyID(IDContextZdroj);
    end;
    MS_DSPresuny.FieldByName('39894481,10.ic_a').AsString := LByID(IDContextCil);
    MS_DSPresuny.FieldByName('39894481,10.u_a').AsString := RbyID(IDContextCil);
    if IDNapVVZdroj <> '' then
    begin
      MS_DSPresuny.FieldByName('39894482,10.ic_a').AsString := LByID(IDNapVVZdroj);
      MS_DSPresuny.FieldByName('39894482,10.u_a').AsString := RbyID(IDNapVVZdroj);
    end;
    if IDNapVVCil <> '' then
    begin
      MS_DSPresuny.FieldByName('39894483,10.ic_a').AsString := LByID(IDNapVVCil);
      MS_DSPresuny.FieldByName('39894483,10.u_a').AsString := RbyID(IDNapVVCil);
    end;
    if IDTridaZdroj <> '' then
    begin
      MS_DSPresuny.FieldByName('39904695,10.ic_a').AsString := LByID(IDTridaZdroj);
      MS_DSPresuny.FieldByName('39904695,10.u_a').AsString := RbyID(IDTridaZdroj);
    end;
    if IDTridaCil <> '' then
    begin
      MS_DSPresuny.FieldByName('39904694,10.ic_a').AsString := LByID(IDTridaCil);
      MS_DSPresuny.FieldByName('39904694,10.u_a').AsString := RbyID(IDTridaCil);
    end;
    MS_DSPresuny.PostNoConfirm;
    ID := MS_DSPresuny.GetPKValue;
    if IDsVytvorenych = '' then
      IDsVytvorenych := ID
    else
      IDsVytvorenych := IDsVytvorenych + ';' + ID;
  end;
  
 
  
begin
  

 // Dingo - start - nespouštět
     // druhy balení přepravních zásilek (260083,10212) -> Druhy statků (6867912,10)
  dingo_sl := TStringList.Create;
  dingo_slIDs := TStringList.Create;
  try
    DingoCreateClass_40043894_10;
    
    // tvorba obsahu tridy "Druhy statku"
    dingo_i := 0;
    StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '260083,10212', ''), ';', dingo_slIDs);
    while dingo_slIDs.Count > dingo_i do
      begin
        // neni v druzich statku
        if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '6867912,10', dingo_slIDs.Strings[dingo_i]) then
          begin
            dingo_sRemoteKey := AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '260083,10212', 'remotekey', dingo_slIDs.Strings[dingo_i]);
            
            // druhy statku
            dingo_sl.Clear;
            dingo_sl.Values['ic'] := LByID(dingo_slIDs.Strings[dingo_i]);
            dingo_sl.Values['u'] := RByID(dingo_slIDs.Strings[dingo_i]);
            dingo_sl.Values['remotekey'] := dingo_sRemoteKey;
            // kod druhu: druh baleni
            dingo_sl.Values['6867921,10'] := AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '133,0', '241,1', dingo_slIDs.Strings[dingo_i]);
            // nazev druhu: nazev druh baleni
            dingo_sl.Values['6867923,10'] := AppServer.GetDBAtrValue(SourceName, rmPrimary, MainLang, '131,0', '236,1', dingo_slIDs.Strings[dingo_i]);
            // popis druhu
            dingo_sl.Values['6867927,10'] := AppServer.GetDBAtrValue(SourceName, rmPrimary, MainLang, '131,0', '263620,10', dingo_slIDs.Strings[dingo_i]);
            //
            AppServer.InsertDBRecord(SourceName, MainLang, '6867912,10', True, dingo_sl);
            
            // kopie multijayzcneho nazvu druhu statku
            DingoCopyDBAtrValue(SourceName, '131,0', '236,1', dingo_slIDs.Strings[0], '6867912,10', '6867923,10', dingo_slIDs.Strings[dingo_i]);
            
            // druhy baleni manipulacnich jednotek
            dingo_sl.Clear;
            dingo_sl.Values['ic'] := LByID(dingo_slIDs.Strings[dingo_i]);
            dingo_sl.Values['u'] := RByID(dingo_slIDs.Strings[dingo_i]);
            dingo_sl.Values['remotekey'] := dingo_sRemoteKey;
            AppServer.InsertDBRecord(SourceName, MainLang, '40043894,10', True, dingo_sl);
          end;
        
        //
        dingo_i := dingo_i + 1;
      end;
    
    // podrizenost tride "druhy statku"
    if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '136,0', '1058477,10212') then
      begin
        dingo_sl.Clear;
        dingo_sl.Values['ic'] := '1058477';
        dingo_sl.Values['u'] := '10212';
        dingo_sl.Values['ic_a'] := '40043894';
        dingo_sl.Values['u_a'] := '10';
        dingo_sl.Values['ic_b'] := '260083';
        dingo_sl.Values['u_b'] := '10212';
        AppServer.InsertDBRecord(SourceName, '', '136,0', True, dingo_sl);
      end;
  finally
    dingo_slIDs.Free;
    dingo_sl.Free;
  end;
 
 
 // BI - skript
  
 AppServer.SetSQLScript(SourceName,TargetPath + 'Reinstall_1100BI.sql');
 
 // BI  - end
 
 
  
  // zruseni druhu baleni prepravnich zasilek ze tridy produkty
  dingo_slIDs := TStringList.Create;
  try
    // zruseni podrizenosti tride "produkty"
    if AppServer.ExistDBKeyValue(SourceName, rmPrimary, '136,0', '260084,10212') then
      AppServer.DeleteDBRecord(SourceName, '136,0', '260084,10212', False);
    
    // mazani zaznamu ze tridy "Produkty"
    dingo_i := 0;
    StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '260083,10212', ''), ';', dingo_slIDs);
    while dingo_slIDs.Count > dingo_i do
      begin
        // existuje ve tride produkty
        if AppServer.ExistDBKeyValue(SourceName, rmPrimary, '133,0', dingo_slIDs.Strings[dingo_i]) then
          // mazani produktu
          AppServer.DeleteDBRecord(SourceName, '133,0', dingo_slIDs.Strings[dingo_i], False);
        
        //
        dingo_i := dingo_i + 1;
      end;
  finally
    dingo_slIDs.Free;
  end;
   // Dingo - end



 
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  M17059359_10;  // NEMAZAT, STANDARDNI SOUCAST REINSTALACE
  
  AppServer.SetSQLScript(SourceName,TargetPath + 'Reinstall_1100AD.sql');
  
  //NESPOUŠTĚT
  // KaSo - naplnění nového atributu "Chyby v dokladu" (40013503,10)ve třídě "Doklady - doplňující údaje" (25748942,10) dle atributu "Nekorektní doklad" (16941578,10)
  SLDoplInfo_KaSo:=TStringList.Create;
  SLDoplnInfoVazba_KaSo:=TStringList.Create;
  DS_KaSo:=TAppDataSet.Create;
  try
    SLDoplInfo_KaSo.Values['40013503,10']:='1';
    DS_KaSo.SetDSParams(SourceName, rmPrimary, '40042982,10', dsaReadNonVisible); //   "Reinstall - doklady a doplňujcí informace "Chyby v dokladu"" (40042532,10)
    DS_KaSo.Open;
    while (not DS_KaSo.EOF) do begin
      IDDokladu_KaSo:=DS_KaSo.GetKeyValue('', ftID);
      IDDoplnInfo_KaSo:=DS_KaSo.GetKeyValue('40042996,10', ftIDB);
      if (IDDoplnInfo_KaSo = '') then begin // Založíme záznam
        AppServer.InsertDBRecord(SourceName, '', '25748942,10', false, SLDoplInfo_KaSo);
        IDDoplnInfo_KaSo:=SLDoplInfo_KaSo.Values['ic'] + ',' + SLDoplInfo_KaSo.Values['u'];
        SLDoplInfo_KaSo.Delete(1);
        SLDoplInfo_KaSo.Delete(1);
        SLDoplnInfoVazba_KaSo.Clear;
        SLDoplnInfoVazba_KaSo.Add('ic_a=' + LByID(IDDokladu_KaSo));
        SLDoplnInfoVazba_KaSo.Add('u_a=' + RByID(IDDokladu_KaSo));
        SLDoplnInfoVazba_KaSo.Add('ic_b=' + LByID(IDDoplnInfo_KaSo));
        SLDoplnInfoVazba_KaSo.Add('u_b=' + RByID(IDDoplnInfo_KaSo));
        AppServer.InsertDBRecord(SourceName, UserLang, '25748957,10', false, SLDoplnInfoVazba_KaSo);
      end else // Nastavíme atribut
        AppServer.SetDBAtrValue(SourceName, '', '25748942,10', '40013503,10', IDDoplnInfo_KaSo, '1');
      DS_KaSo.Next;
    end;
  finally
    DS_KaSo.Free;
    SLDoplnInfoVazba_KaSo.Free;
    SLDoplInfo_KaSo.Free;
  end;
  // KaSo - end

  // NESPOUŠTĚT
  // AV1 - Přesun atributu z třídy "Doklady" (3804,10) do "Doklady - doplňující údaje" (25748942,10)
  AV1_DS := TAppDataSet.Create;
  try
    AV1_DS.SetDSParams(SourceName, rmPrimary, '39910145,10', dsaFullNonVisible, '', '', '', '"39910150,10" <> ''''');
    AV1_DS.Open;
    //
    while not AV1_DS.EOF do
    begin
      AV1_DS.Edit;
      AV1_DS.FieldByName('39910149,10').AsString := AV1_DS.FieldByName('39910150,10').AsString;
      AV1_DS.PostNoConfirm;
      AV1_DS.Next;
    end;
  finally
    AV1_DS.Free;
  end;
  // AV1 - konec
  
  //NESPOUŠTĚT
  //VKo - nastavení GK Financí //nový atribut "Výchozí nárok na odpočet DPH"
  sTemp := AppServer.GetDBKeyValues(SourceName, rmPrimary, '15777,10', '');
  if (sTemp <> '') then
    AppServer.SetDBAtrValue(SourceName, '', '15777,10', '39911664,10', sTemp, '0');
  //VKo - konec
  
  //LuP - 01: naplneni udaju "Na vydeji ze skladovych dokladu" ve stavech zasob za umisteni (NESPOUSTET)
  LuP_SL := TStringList.Create;
  try
    AppServer.GetAKLicSL(LuP_SL);
    while LuP_Index < LuP_SL.Count do begin
      if LuP_Filter = '' then
        LuP_Filter := LuP_SL.Strings[LuP_Index]
      else
        LuP_Filter := LuP_Filter + ',' + LuP_SL.Strings[LuP_Index];
      //
      LuP_Index := LuP_Index + 1;
    end;
    if LuP_Filter <> '' then
      LuP_Filter := '"u" in (' + LuP_Filter + ')';
  finally
    LuP_SL.Free;
  end;
  LuP_DS := TAppDataSet.Create;
  try
    LuP_DS.SetDSParams(SourceName, rmPrimary, '39913885,10', dsaFullNonVisible);
    LuP_DS.Filter := LuP_Filter;
    LuP_DS.Open;
    while not LuP_DS.EOF do begin
      LuP_Prep := LuP_DS.FieldByName('39915314,10').AsString;
      if LuP_Prep = '1' then
        LuP_Prep := '0'
      else
        LuP_Prep := '1';
      LuP_ID := LuP_DS.GetKeyValue('39913901,10', ftID);
        if LuP_ID <> '' then
          AppServer.DeleteDBRecord(SourceName, '10298574,10', LuP_ID, false);
        AppServer.SetDBAtrValue(SourceName, '', '950437,10', '10298831,10', LuP_DS.GetKeyValue('', ftID), LuP_Prep);
      //
      LuP_DS.Next;
    end;
  finally
    LuP_DS.Free;
  end;
  LuP_DS := TAppDataSet.Create;
  try
    LuP_DS.SetDSParams(SourceName, rmPrimary, '39913865,10', dsaReadNonVisible);
    LuP_DS.Filter := LuP_Filter;
    LuP_DS.Open;
    while not LuP_DS.EOF do begin
      LuP_Prep := LuP_DS.FieldByName('39915315,10').AsString;
      if LuP_Prep = '1' then
        LuP_Prep := '0'
      else
        LuP_Prep := '1';
      LuP_ID := LuP_DS.GetKeyValue('39913866,10', ftID);
      if LuP_ID <> '' then
        AppServer.DeleteDBRecord(SourceName, '10254729,10', LuP_ID, false);
      AppServer.SetDBAtrValue(SourceName, '', '950436,10', '37859851,10', LuP_DS.GetKeyValue('', ftID), LuP_Prep);
       //
      LuP_DS.Next;
    end;
  finally
    LuP_DS.Free;
  end;
  //LuP - 01: end
  
  //LuP - 02: udrzba obsazenosti manipulacnich jednotek ve stavech zasob (NESPOUSTET)
    //vymaz chybnych vazeb na zaklade manipulacnich jednotek
  LuP_ContenctMNUDS := TAppDataSet.Create;
  try
    LuP_ContenctMNUDS.SetDSParams(SourceName, rmPrimary, '39911992,10', dsaReadNonVisible);
    LuP_ContenctMNUDS.Filter := '("39920590,10.ic" is not null and "39920590,10.u" is not null) and '
                               //vazba existuje
                            + '(("40236249,10.ic" is not null and "40236249,10.ic" is not null) or ' //je v nadrizene, ktera ma sklad
                               //nebo platna vazba
                            + '((("39921926,10" is not null and "39921926,10" <> 0) or '
                            +   '("39921927,10" is not null and "39921927,10" <> 0) or '
                            +   '("39921928,10" is not null and "39921928,10" <> 0) or '
                            +   '("39921929,10" is not null and "39921929,10" <> 0)) and ' 
                               //a
                            +  '(("39911997,10.ic" is null and "39911997,10.u" is null) or '  //MNJ nema sklad
                            +   '("39922240,10" is null or not "39922240,10" in (1,2)))) or ' //nebo MNJ nema prislusny stav
                               //nebo platna vazba pro umisteni
                            +  '((("39921928,10" is not null and "39921928,10" <> 0) or '
                            +    '("39921929,10" is not null and "39921929,10" <> 0)) and '
                            +   '("39911998,10.ic" is null and "39911998,10.u" is null)))';    //a MNJ nema umisteni

    LuP_ContenctMNUDS.Open;
    if not LuP_ContenctMNUDS.IsEmpty then begin
      while not LuP_ContenctMNUDS.EOF do begin
        LuP_ID := LuP_ContenctMNUDS.GetKeyValue('39920590,10', ftID);
        AppServer.DeleteDBRecord(SourceName, '39911815,10', LuP_ID, false);
        //
        LuP_ContenctMNUDS.Next;
      end;
    end;
  finally
    LuP_ContenctMNUDS.Free;
  end;
  //
  //vymaz chybnych vazeb na zaklade polozek dokladu
  LuP_DocumentItems := TAppDataSet.Create;
  try
    LuP_DocumentItems.SetDSParams(SourceName, rmPrimary, '39974474,10', dsaReadNonVisible);
    LuP_DocumentItems.Filter := '("39974502,10.ic" is not null and "39974502,10.u" is not null and '
                              +  '"39974509,10" is not null and "39974509,10" <> 0) and '
                                //vazba existuje a je na ni platne mnozstvi
                              + '(("39974505,10" = 1) or '
                              +  '(not("39974504,10" in (1,2))) or '
                                 //MNJ je rozbalena nebo nejde o polozku s pripojenou MNJ  
                              +  '("39974493,10.ic" is null and "39974493,10.u" is null and '
                              +   '"39974492,10.ic" is null and "39974492,10.u" is null) or '
                                 //nejde o vydejku ani o posk. plneni
                              +  '("39974493,10.ic" is not null and "39974493,10.u" is not null and '
                              +   '("39974506,10" is null or not("39974506,10" in (0,-1)) or '
                              +   '("39974513,10.ic" is not null and "39974513,10.u" is not null))) or '
                                 //jde o vydejku, ktera je promitnuta do stavu zasob, 
                                 //               nebo je castecne promitnuta a ma vazbu na stav zasob
                              +  '("39974492,10.ic" is not null and "39974492,10.u" is not null and '
                              +   '("39974518,10" is null or "39974522,10" is null or "39974522,10" <= 0)))';
                                 //jde o posk. plneni, ktere neni DLV
                                 //                    nebo zbyva dodat je nulove
    LuP_DocumentItems.Open;
    if not LuP_DocumentItems.IsEmpty then begin
      while not LuP_DocumentItems.EOF do begin
        LuP_ID := LuP_DocumentItems.GetKeyValue('39974502,10', ftID);
        AppServer.DeleteDBRecord(SourceName, '39923583,10', LuP_ID, false);
        //
        LuP_DocumentItems.Next;
      end;
    end;
  finally
    LuP_DocumentItems.Free;
  end;
  //
  //vymaz chybnych vazeb na zaklade rozpadu polozek dokladu
  LuP_DocumentItems := TAppDataSet.Create;
  try
    LuP_DocumentItems.SetDSParams(SourceName, rmPrimary, '39974557,10', dsaReadNonVisible);
    LuP_DocumentItems.Filter := '("39974569,10.ic" is not null and "39974569,10.u" is not null and '
                              +  '"39974570,10" is not null and "39974570,10" <> 0) and '
                                //vazba existuje a je na ni platne mnozstvi
                              + '(("39974562,10" = 1) or '
                              +  '(not("39974561,10" in (1,2))) or '
                                 //MNJ je rozbalena nebo nejde o polozku s pripojenou MNJ  
                              +  '("39974568,10.ic" is null and "39974568,10.u" is null and '
                              +   '"39974566,10.ic" is null and "39974566,10.u" is null) or '
                                 //nejde o vydejku ani o posk. plneni
                              +  '("39974568,10.ic" is not null and "39974568,10.u" is not null and '
                              +   '("39974565,10" is null or not("39974565,10" in (0,-1)) or '
                              +   '("39974571,10.ic" is not null and "39974571,10.u" is not null))) or '
                                 //jde o vydejku, ktera je promitnuta do stavu zasob, 
                                 //               nebo je castecne promitnuta a ma vazbu na stav zasob
                              +  '("39974566,10.ic" is not null and "39974566,10.u" is not null and '
                              +   '("39974567,10" is null or "39974596,10" = 0)))';
                                 //jde o posk. plneni, ktere neni DLV
                                 //                    nebo zbyva dodat je nulove
    LuP_DocumentItems.Open;
    if not LuP_DocumentItems.IsEmpty then begin
      while not LuP_DocumentItems.EOF do begin
        LuP_ID := LuP_DocumentItems.GetKeyValue('39974569,10', ftID);
        AppServer.DeleteDBRecord(SourceName, '39923584,10', LuP_ID, false);
        //
        LuP_DocumentItems.Next;
      end;
    end;
  finally
    LuP_DocumentItems.Free;
  end;
  //
  //prepocet na zaklade manipulacnich jednotek
  LuP_ContenctMNUDS := TAppDataSet.Create;
  try
    LuP_ContenctMNUDS.SetDSParams(SourceName, rmPrimary, '39911992,10', dsaReadNonVisible);
    LuP_Filter := '("39911997,10.ic" is not null and "39911997,10.u" is not null) and '
            + '("39912012,10.ic" is not null and "39912012,10.u" is not null) and '
            + '("39922240,10" is not null and "39922240,10" in (1,2)) and '
            + '("39912048,10" is not null and "39912048,10" > 0)';
    LuP_Filter := '(' + LuP_Filter + ')';
    LuP_ContenctMNUDS.Filter := LuP_Filter;  
    LuP_ContenctMNUDS.Open;
    if not LuP_ContenctMNUDS.IsEmpty then begin
      while not LuP_ContenctMNUDS.EOF do begin
        LuP_Switch := LuP_ContenctMNUDS.FieldByName('39923049,10').AsString;
        if LuP_Switch = '1' then
          LuP_Switch := '0'
        else
          LuP_Switch := '1';
        AppServer.SetDBAtrValue(SourceName, '', '30610999,10', '39911813,10', LuP_ContenctMNUDS.GetKeyValue('', ftID), LuP_Switch);
        //
        LuP_ContenctMNUDS.Next;
      end;
    end;
  finally
    LuP_ContenctMNUDS.Free;
  end;
  //
  //prepocet na zaklade polozek dokladu
  LuP_DocumentItems := TAppDataSet.Create;
  try
    LuP_DocumentItems.SetDSParams(SourceName, rmPrimary, '39974474,10', dsaReadNonVisible);
    LuP_Filter := 'not ("39974493,10.ic" is null and "39974493,10.u" is null and '
            +       '"39974492,10.ic" is null and "39974492,10.u" is null) and '
            + '("39974505,10" is null or "39974505,10" = 0) and '
            + '("39974504,10" in (1,2)) and '
            + '(("39974493,10.ic" is not null and "39974493,10.u" is not null and '
            +   '"39974506,10" in (0,-1) and '
            +   '"39974513,10.ic" is null and "39974513,10.u" is null) or '
            +  '("39974492,10.ic" is not null and "39974492,10.u" is not null and '
            +   '"39974518,10" is not null and '
            +   '"39974522,10" is not null and "39974522,10" > 0))';
    LuP_Filter := '(' + LuP_Filter + ')';
    LuP_DocumentItems.Filter := LuP_Filter;  
    LuP_DocumentItems.Open;
    if not LuP_DocumentItems.IsEmpty then begin
      while not LuP_DocumentItems.EOF do begin
        LuP_ISwitch := LuP_DocumentItems.FieldByName('39974719,10').AsInteger;
        if LuP_ISwitch < 2 then
          LuP_Switch := '2'
        else
          LuP_Switch := IntToStr(LuP_ISwitch + 1);
        AppServer.SetDBAtrValue(SourceName, '', '29558,10', '39924606,10', LuP_DocumentItems.GetKeyValue('', ftID), LuP_Switch);       
        //
        LuP_DocumentItems.Next;
      end;
    end;
  finally
    LuP_DocumentItems.Free;
  end;
  //LuP - 02: end
  
  // ZS - naplneni kodu CZEM statu bydliste u zamestnancu (NESPOUSTET)
  if (legislation = '745998,10') then
  begin
    DSEmpl := TAppDataSet.Create;
    try
      // DS Zamestnanci - vyplnen stat trvaleho bydliste a neni vyplnen kod CZEM statu
      DSEmpl.SetDSParams(SourceName, rmPrimary, '72027,10', dsaReadNonVisible, '', '', '', '"25090607,10.ic" IS NOT NULL AND "200968,9" IS NULL');
      DSEmpl.NoMacros := true;
      DSEmpl.Open;
      while not DSEmpl.EOF do
      begin
        idState := DSEmpl.GetKeyValue('25090607,10', ftIDA);
        if AppServer.ExistDBKeyValue(SourceName, rmPrimary, '3107,10', idState) then
        begin
          str := AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '3107,10', '819516,10', idState);
          if (str <> '') then
            AppServer.SetDBAtrValue(SourceName, '', '17684,10', '200966,9', DSEmpl.GetKeyValue('454295,10', ftID), str);
        end;
        
        DSEmpl.Next;  // dalsi zamestnanec
      end;
    finally
      DSEmpl.Free;
    end;
    str := '';
  end;
  // ZS konec
  
  // ZS - naplneni emailu a telefonu pro podepisovani Signi u vytvorenych ELDP (NESPOUSTET)
  if (legislation = '745998,10') then
  begin
    DSEldp := TAppDataSet.Create;
    try
      // DS ELDP
      DSEldp.SetDSParams(SourceName, rmprimary, '2560321,10', dsaFullNonVisible, '', '', '', '"6108108,10" > 2022');
      DSEldp.NoMacros := true;
      DSEldp.Open;
      while not DSEldp.EOF do
      begin
        idPpv := DSEldp.GetKeyValue('', ftIDA);
        
        // Druh vydelecne cinnosti
        str := AppServer.GetDBKeyValue(SourceName, rmPrimary, '14135163,10', idPpv, ftIDA, ftIDB);
        if (str <> '') then
          typePpv := AppServer.GetDBAtrValue(SourceName, rmPrimary, UserLang, '14135162,10', '14135172,10', str);
        
        // datum skutecneho nastupu
        dateRealStartPpv := ANSIStrToDate(AppServer.GetDBAtrValue(SourceName, rmPrimary, UserLang, '446925,10', '29027249,10', IDPpv));
        
        // info o PPV
        M1618921_10(idPpv, DSEldp.GetKeyValue('14801489,10', ftID), DSEldp.FieldByName('6108108,10').AsString,
                    typeppv, dateRealStartPpv, mr, rc, StreetEmpl, NumEmpl, post, psc, email, phone, ActivFrom, dpp);
        if (DSEldp.FieldByName('37988575,10').AsString <> '') then
          email := DSEldp.FieldByName('37988575,10').AsString;
        if ((email <> '') or (phone <> '')) then
        begin
          DSEldp.Edit;
          if (email <> '') then
            DSEldp.FieldByName('40043221,10').AsString := email;
          if (phone <> '') then
            DSEldp.FieldByName('40043222,10').AsString := phone;
          DSEldp.PostNoConfirm;
        end;
        
        DSEldp.Next;  // dalsi ELDP
      end;
    finally
      DSEldp.Free;
    end;
  end;
  // ZS konec
  
  // MP - úprava atributu "Akce snímače"   - NESPOUŠTĚT
  MP_DSNasnData := TAppDataSet.Create;
  try
    MP_DSNasnData.SetDSParams(SourceName, rmPrimary, '29551980,10', dsaViewNonVisible);  // "Nasnímaná data - vše" 
    MP_DSNasnData.Filter := '"29551983,10"=1';
    MP_DSNasnData.Open;
    while not MP_DSNasnData.EOF do
    begin
      AppServer.SetDBAtrValue(SourceName, '', '23483,10218', '23504,10218', MP_DSNasnData.GetPKValue, '0');
      MP_DSNasnData.Next;
    end;
  finally
    MP_DSNasnData.Free;
  end;  
  // MP - konec

  //ViKu - naplneni moveho atributu "Datove podklady" (NESPOUSTET)
  //vsechny zaznamy, ktere jsou v DT "11691774,10"
  QIG_VK_SL_ID := TStringList.Create;
  try
    //jen zaznamy z podridy "Rozpousteni"
    QIG_VK_Data := AppServer.GetDBKeyValues(SourceName,rmPrimary,'11691774,10','');
    StringToSL(QIG_VK_Data,';',QIG_VK_SL_ID);
    if QIG_VK_SL_ID.Count > 0 then
    begin
      QIG_VK_i := 0;
      while QIG_VK_i < QIG_VK_SL_ID.Count do
      begin
        QIG_VK_ID := QIG_VK_SL_ID.Strings[QIG_VK_i];
        //Nastaveni údaje "Datove podklady" v DT "Rozpouštění a přeúčtování"
        //doposud vsechny prazdne zaznamy byly "Standardni"
        if AppServer.GetDBAtrValue(SourceName,rmPrimary,UserLang,'2763253,10','39987960,10',QIG_VK_ID) = '' then
          AppServer.SetDBAtrValue(SourceNAme,UserLang,'2763253,10','39987960,10',QIG_VK_ID,'0');
        QIG_VK_i :=  QIG_VK_i + 1;
      end;
    end;
  finally
    QIG_VK_SL_ID.Free;
  end;
  //ViKu - konec
  
  // MP - parametry statků - změna hodnot atributu "Typ parametru"   - NESPOUŠTĚT
  MP_DSParam := TAppdataSet.Create;
  try       
    // DS "Charakteristiky a měřené veličiny statků" 
    MP_DSParam.SetDSParams(SourceName, rmPrimary, '12626110,10', dsaEditNonVisible); 
    MP_DSParam.NoMacros := true;
    MP_DSParam.Open;
    while not MP_DSParam.EOF do      
    begin
      case
        not MP_DSParam.FieldByName('12626112,10.ic').IsNull:  // jedná se o měřenou veličinu
        begin
          MP_DSParam.Edit;
          MP_DSParam.FieldByName('12639277,10').AsInteger := 0; // Měřená veličina
          MP_DSParam.PostNoConfirm;
        end;
        not MP_DSParam.FieldByName('12626114,10.ic').IsNull and (MP_DSParam.FieldByName('12639277,10').AsInteger = 0):  // jedná se o charakteristiku a není povol. uživ. hodn.
        begin
          MP_DSParam.Edit;
          MP_DSParam.FieldByName('12639277,10').AsInteger := 1; // Existence
          MP_DSParam.PostNoConfirm;
        end;
        not MP_DSParam.FieldByName('12626114,10.ic').IsNull and (MP_DSParam.FieldByName('12639277,10').AsInteger = 1):  // jedná se o charakteristiku a jsou povol. uživ. hodn.
        begin
          MP_DSParam.Edit;
          MP_DSParam.FieldByName('12639277,10').AsInteger := 2; // uživ. hodnoty
          MP_DSParam.PostNoConfirm;
        end;        
      end;
      MP_DSParam.Next;
    end;
  finally
    MP_DSParam.Free;
  end; 
  // MP - konec
  
  // ZS - naplneni cerpani dovolene v obdobi a oznaceni MS (NESPOUSTET)
  if (legislation = '745998,10') then
  begin
    idPer := AppServer.GetDBKeyValues(SourceName, rmPrimary, '450391,10', '"451082,10" = 0');  // posledni obdobi
    if (idPer <> '') then
    begin
      // vypocet cerpani dovolene pro jednotliva obdobi posledniho roku
      dateStartPer := ANSIStrToDate(AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '450391,10', '546181,10', idPer));
      DecodeDate(dateStartPer, year, month, day);
      dateStartYear := EncodeDate(year, 1, 1);
      
      DSMS := TAppDataSet.Create;
      DSPar := TAppDataSet.Create;
      try
        // DS Mesicni MS-soucty celkem makra
        DSMS.SetDSParams(SourceName, rmPrimary, '469465,10', dsaViewNonVisible);
        DSMS.OpenEmpty;
        // DS PPV parametry-pro makra, parametry v poslednim roce
        DSPar.SetDSParams(SourceName, rmPrimary, '13200684,10', dsaViewNonVisible, '', '', '',
                          Format('("13201326,10" >= ''%%'') AND ("13201326,10" < ''%%'')',
                                 [DateToANSIStr(dateStartYear), DateToANSIStr(DateAdd(dpYear, 1, dateStartYear))]));
        DSPar.Open;
        while not DSPar.EOF do
        begin
          holidayDraw := 0;
          
          // Cerpani dovolene v aktualnim obdobi
          // 1. PPV
          // 2. obdobi
          // 3. MS 521, 524
          DSMS.Filter := Format('("ic_a" = %%) AND ("u_a" = %%) AND ("ic_b" = %%) AND ("u_b" = %%) AND
                                 (("469709,10" = ''521'') OR ("469709,10" = ''524''))',
                                [DSPar.FieldByName('ic_a').AsString, DSPar.FieldByName('u_a').AsString,
                                 DSPar.FieldByName('ic_b').AsString, DSPar.FieldByName('u_b').AsString]);
          while not DSMS.EOF do
          begin
            AppServer.SetDBAtrValue(SourceName, '', '460561,10', '40119512,10', DSMS.GetPKValue, '1'); // oznaceni MS priznakem Dovolena
            holidayDraw := holidayDraw + DSMS.FieldByName('469478,10').AsFloat;                        // hodiny dovolene z MS
            
            DSMS.Next;  // dalsi MS
          end;
          
          // zapis cerpani dovolene v danem obdobi
          AppServer.SetDBAtrValue(SourceName, '', '450459,10', '40119517,10', DSPar.GetPKValue, FloatToANSIStr(holidayDraw));
          
          DSPar.Next;  // dalsi mzdove udaje
        end;
      finally
        DSMS.Free;
        DSPar.Free;
      end;
    end;
  end;
  // konec ZS
  
  // ZS - naplneni udaje Omezit mesicni prispevek (zivotni pojisteni) (NESPOUSTET)
  if (legislation = '745998,10') then
  begin
    SL := TSTringList.Create;
    try
      StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '450459,10', ''), ';', SL);
      i := 0;
      while (i < SL.Count) do
      begin
        AppServer.SetDBAtrValue(SourceName, '', '450459,10', '40142335,10', SL.Strings[i], '0');
        
        i := i + 1;  // dalsi mzdove udaje
      end;
    finally
      SL.Free;
    end;
  end;
  // ZS konec
  
  // ZS - naplneni udaje Rozpad zakonneho pojisteni na dimenze (SPUSTIT)
  if (legislation = '745998,10') then
  begin
    SL := TStringList.Create;
    try
      StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '450391,10', ''), ';', SL);
      i := 0;
      while (i < SL.Count) do
      begin
        AppServer.SetDBAtrValue(SourceName, '', '450391,10', '40165831,10', SL.Strings[i], '2');  // Plny rozpad
        
        i := i + 1;  // dalsi obdobi
      end;
    finally
      SL.Free;
    end;
  end;
  // ZS konec
  
  // ZS nastaveni vypoctovych vzorecku MS 776 (NESPOUSTET)
  if (legislation = '745998,10') then
    if AppServer.ExistDBKeyValue(SourceName, rmPrimary, '18144,10', '2410547,9') then
    begin
      idPer := AppServer.GetDBKeyValues(SourceName, rmPrimary, '450391,10', '"451082,10" = 0');  // posledni obdobi
      if (AppServer.GetDBLinkKeyValue(SourceName, rmPrimary, '599542,10', '2410547,9', idPer) = '') then
      begin
        SL := TStringList.Create;
        try
          // vazba vzorecku na obdobi
          SL.Clear;
          SL.Add('ic_a=2410547');
          SL.Add('u_a=9');
          SL.Add('ic_b='+LByID(idPer));
          SL.Add('u_b='+RByID(idPer));
          AppServer.InsertDBRecord(SourceName, '', '599542,10', false, SL);
          ic := SL.Values['ic'];
          u := SL.Values['u'];
          // vypocet sazby - vazba na vzorecek Konstanta
          SL.Clear;
          SL.Add('ic_a='+ic);
          SL.Add('u_a='+u);
          SL.Add('ic_b=601403');
          SL.Add('u_b=10');
          AppServer.InsertDBRecord(SourceName, '', '599797,10', false, SL);
          // vypocet castky - vazba na vzorecek Hodiny  * Sazba
          SL.Clear;
          SL.Add('ic_a='+ic);
          SL.Add('u_a='+u);
          SL.Add('ic_b=601497');
          SL.Add('u_b=10');
          AppServer.InsertDBRecord(SourceName, '', '599808,10', false, SL);
        finally
          SL.Free;
        end;
      end;
    end;
  // ZS konec
  
  // ViKo (NESPOUSTET)
  // Reinstalační makro 110.0 - naplnění údaje "Čerpáno" u ZLP
  M40126746_10;
  // ViKo -konec
  
  // MaSu - Reinstalace procesních přesunů (NESPOUSTET)
  MS_Node := GetUserGlobals('','647187,10','');
  if (MS_Node <> '10') and (MS_Node <> '9999') then
  begin
    MS_DS := TAppDataSet.Create;
    MS_SL := TStringList.Create;
    MS_SLText := TStringList.Create;
    MS_DSPresuny := TAppDataSet.Create;
    try
      //Kontextové procesní přesuny
      MS_DSPresuny.SetDSParams(SourceName,rmPrimary,'39894478,10',dsaFullNonVisible);
      MS_DSPresuny.NoMacros := true;
      MS_DSPresuny.OpenEmpty;
      MS_SLText.Add('BEGIN (Reinstall 6385476,10 --> 39894462,10)');
      //Reinstall 110.0 - Přesun vstupu/výstupu
      MS_DS.SetDSParams(SourceName,rmPrimary,'26315044,10',dsaReadNonVisible);
      MS_DS.Open;
      while not MS_DS.EOF do
      begin
        MS_IDsPres := '';
        StringToSL(AppServer.GetDBLinkKeyValue(SourceName, rmPrimary, '227676,10', MS_DS.GetKeyValue('26315045,10',ftIDA), MS_DS.GetKeyValue('26315048,10',ftIDA)),';',MS_SL);
        if MS_SL.Count > 0 then
        begin
          MS_i := 0;
          while MS_i < MS_SL.Count do
          begin
            MS_VytvorPresun(true,'',MS_SL.Strings[MS_i],MS_DS.GetKeyValue('26315048,10',ftID),MS_DS.GetKeyValue('26315045,10',ftID),'','',MS_IDsPres);
            MS_i := MS_i + 1;
          end;
        end else
        begin
          MS_GetKontexty(MS_DS.GetKeyValue('26315048,10',ftIDA),MS_DS.GetKeyValue('26315045,10',ftIDA),MS_SL);
          MS_i := 0;
          while MS_i < MS_SL.Count do
          begin
            MS_VytvorPresun(false,ElemByIndex(MS_SL.Strings[MS_i],0,';'),ElemByIndex(MS_SL.Strings[MS_i],1,';'),MS_DS.GetKeyValue('26315048,10',ftID),MS_DS.GetKeyValue('26315045,10',ftID),'','',MS_IDsPres);
            MS_i := MS_i + 1;
          end;
        end;
        if MS_IDsPres = '' then 
          MS_IDsPres := '???';
        MS_SLText.Add('  ' + MS_DS.GetPKValue + ' --> ' + MS_IDsPres);
        MS_DS.Next;
      end;
      MS_DS.Close;
      MS_SLText.Add('END (Reinstall 6385476,10 --> 39894462,10)');
      MS_SLText.Add('BEGIN (Reinstall 23273425,10 --> 39894462,10)');
      //Reinstall 110.0 - Proces pro převzetí realizátora
      MS_DS.SetDSParams(SourceName,rmPrimary,'39990170,10',dsaReadNonVisible);
      MS_DS.Open;
      while not MS_DS.EOF do
      begin
        MS_IDsPres := '';
        MS_SL.Clear;
        if (MS_DS.GetKeyValue('39990173,10',ftID) = '') and (MS_DS.GetKeyValue('39990380,10',ftIDB) = '10582733,10') then
        begin
          StringToSL(AppServer.GetDBLinkKeyValue(SourceName, rmPrimary, '227676,10', MS_DS.GetKeyValue('',ftIDA), MS_DS.GetKeyValue('',ftIDB)),';',MS_SL);
          MS_i := 0;
          while MS_i < MS_SL.Count do
          begin
            MS_VytvorPresun(true,'',MS_SL.Strings[MS_i],'','','39975202,10','39904864,10',MS_IDsPres);
            MS_i := MS_i + 1;
          end;
        end;
        if MS_SL.Count = 0 then
        begin
          MS_GetKontexty(MS_DS.GetKeyValue('',ftIDB),MS_DS.GetKeyValue('',ftIDA),MS_SL);
          MS_i := 0;
          while MS_i < MS_SL.Count do
          begin
            if MS_DS.GetKeyValue('39990173,10',ftID) <> '' then
              MS_VytvorPresun(false,ElemByIndex(MS_SL.Strings[MS_i],0,';'),ElemByIndex(MS_SL.Strings[MS_i],1,';'),'','','39904869,10','39904864,10',MS_IDsPres)
            else
              if MS_DS.GetKeyValue('39990380,10',ftIDB) = '10582733,10' then
                MS_VytvorPresun(false,ElemByIndex(MS_SL.Strings[MS_i],0,';'),ElemByIndex(MS_SL.Strings[MS_i],1,';'),'','','39975202,10','39904864,10',MS_IDsPres);
            MS_i := MS_i + 1;
          end;
        end;
        if MS_IDsPres = '' then 
          MS_IDsPres := '???';
        MS_SLText.Add('  ' + MS_DS.GetPKValue + ' --> ' + MS_IDsPres);
        MS_DS.Next;
      end;
      MS_DS.Close;
      MS_SLText.Add('END (Reinstall 23273425,10 --> 39894462,10)');
      MS_SLText.Add('BEGIN (Reinstall 30297894,10 --> 39894462,10)');
      //Reinstall 110.0 - Vykonávají ze vstupů
      MS_DS.SetDSParams(SourceName,rmPrimary,'39990382,10',dsaReadNonVisible);
      MS_DS.Open;
      while not MS_DS.EOF do
      begin
        MS_IDsPres := '';
        StringToSL(AppServer.GetDBKeyValue(SourceName,rmPrimary,'227676,10',MS_DS.GetKeyValue('39990385,10',ftID),ftIDA,ftID),';',MS_SL);
        MS_i := 0;
        while MS_i < MS_SL.Count do
        begin
          MS_VytvorPresun(false,MS_SL.Strings[MS_i],MS_SL.Strings[MS_i],MS_DS.GetKeyValue('39990384,10',ftID),'',MS_DS.GetKeyValue('',ftIDB),'39904864,10',MS_IDsPres);
          MS_i := MS_i + 1;
        end;
        if MS_IDsPres = '' then 
          MS_IDsPres := '???';
        MS_SLText.Add('  ' + MS_DS.GetPKValue + ' --> ' + MS_IDsPres);
        MS_DS.Next;
      end;
      MS_SLText.Add('END (Reinstall 30297894,10 --> 39894462,10)');
      M25557007_10('1503411', '10', 'Reinstalace procesních přesunů', SLToString(MS_SLText,#13#10));
    finally
      MS_DS.Free;
      MS_SL.Free;
      MS_SLText.Free;
      MS_DSPresuny.Free;
    end;
  end;
  // MaSu - konec
  
  // MP - Naplnění externího kódu statku z Části ME   - NESPOUŠTĚT
  MP_SLExKod := TStringList.Create;
  try
    StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '639073,10103', '"639137,10103" is not null'), ';', MP_SLExKod);  // "Části majetkové evidence", kde "GIS objekt" je vyplněný
    MP_Index := 0;  
    while MP_Index < MP_SLExKod.Count do
    begin
      MP_IDStatku := MP_SLExKod.Strings[MP_Index];
      MP_Kod := AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '639073,10103', '639137,10103', MP_IDStatku);
      AppServer.SetDBAtrValue(SourceName, '', '131,0', '40215898,10', MP_IDStatku, MP_Kod);  // Do "Externí kód" u Statku
      MP_Index := MP_Index + 1;
    end;
  finally
    MP_SLExKod.Free;
  end;  
  // MP - konec 
  
  // MaSu - Plnění atr. "Povinný" u napojených vstupů/výstupů (NESPOUSTET)
  SL := TStringList.Create;
  try
    StringToSL(AppServer.GetDBKeyValues(Sourcename,rmPrimary,'6313673,10',''),';',SL); 
    i := 0;
    while i < SL.Count do
    begin
      AppServer.SetDBAtrValue(SourceName,'','6313673,10','40212847,10',SL.Strings[i],'1');
      i := i + 1;
    end;
  finally
    SL.Free;
  end;
  // MaSu - konec

  //OK (NESPOUSTET)
  //Progr.funkce: Kalkulator norem - Reinstall 110.0 - Naplneni MJ cinnosti a ukonu (Makra)
  M40081269_10(7);
  
  //PM - nastaveni vychoziho statu konfigurace QI Portalu (NESPOUŠTĚT)
  Case
    Legislation='745998,10': PM_IDState := AppServer.GetDBKeyValues(SourceName,rmPrimary,'3107,10','("5469,10"=''CZE'')');
    Legislation='740878,10': PM_IDState := AppServer.GetDBKeyValues(SourceName,rmPrimary,'3107,10','("5469,10"=''SVK'')');
  end;
  PM_IDs := AppServer.GetDBKeyValues(SourceName,rmPrimary,'5533,20','');
  if (PM_IDState<>'') and (PM_IDs<>'') then begin
    PM_SL := TStringList.Create;
    try
      PM_i:=0;
      while GetElemCount(PM_IDs,';')>PM_i do begin
        PM_IDConf := ElemByIndex(PM_IDs,PM_i,';');
        if not AppServer.ExistDBKeyValue(SourceName,rmPrimary,'40217638,10',PM_IDConf,ftIDB) then begin
          PM_SL.Clear;
          PM_SL.Add('ic_a='+LByID(PM_IDState));
          PM_SL.Add('u_a='+RByID(PM_IDState));
          PM_SL.Add('ic_b='+LByID(PM_IDConf));
          PM_SL.Add('u_b='+RByID(PM_IDConf));
          PM_SL.Add('40221011,10=1');
          AppServer.InsertDBRecord(SourceName,UserLang,'40217638,10',False,PM_SL);
        end;
        PM_i:= PM_i + 1;
      end;
    finally
      PM_SL.Free;
    end;
  end;
  
  // AV - toto makro způsobovalo pád aplikace, bylo vypuštěno z reinstalace a bylo nahrazeno opravou do vezre 110.2
  {// AV2 - začátek (Nespouštět) 
  M29212145_10;
  // AV2 - konec }
  
  
  // Dingo - Start - nespouštět
  // WMS: tvorba roli WMS pro uzivatele
  dingo_sl := TStringList.Create;
  dingo_UserIDs := TStringList.Create;
  dingo_SectorIDs := TStringList.Create;
  try
    // nacteni uzivatelu pro tvorbu roli WMS
    DingoAppendIDToSL(AppServer.GetDBKeyValuesEx(SourceName, rmPrimary, '308850,11011', '', '', [], '', 0, ftIDB, 0, True), dingo_UserIDs);
    DingoAppendIDToSL(AppServer.GetDBKeyValuesEx(SourceName, rmPrimary, '306945,11011', '', '', [], '', 0, ftIDB, 0, True), dingo_UserIDs);
    DingoAppendIDToSL(AppServer.GetDBKeyValuesEx(SourceName, rmPrimary, '306946,11011', '', '', [], '', 0, ftIDB, 0, True), dingo_UserIDs);
    
    //
    while dingo_UserIDs.Count > 0 do
      begin
        if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '457363,11011', dingo_UserIDs.Strings[0], ftIDA) then
          if AppServer.GetDBKeyValues(SourceName, rmPrimary, '457355,11011', Format('"remotekey" = ''%%''', [dingo_UserIDs.Strings[0]])) = '' then
            begin
              // nacteni: prihlasovaci ucet
              dingo_UserName := AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '111,0', '272,0', dingo_UserIDs.Strings[0]);
              
              // tvorba role WMS
              dingo_sl.Clear;
              dingo_sl.Values['remotekey'] := dingo_UserIDs.Strings[0];
              dingo_sl.Values['46136,10015'] := dingo_UserName;
              dingo_sl.Values['236,1'] := Format('Role WMS [%%]', [dingo_UserName]);
              AppServer.InsertDBRecord(SourceName, MainLang, '457355,11011', False, dingo_sl);
              dingo_RoleID := Format('%%,%%', [dingo_sl.Values['ic'], dingo_sl.Values['u']]);
              
              // aktivni role WMS prihlasovaciho uctu
              dingo_sl.Clear;
              dingo_sl.Values['ic_a'] := LByID(dingo_UserIDs.Strings[0]);
              dingo_sl.Values['u_a'] := RByID(dingo_UserIDs.Strings[0]);
              dingo_sl.Values['ic_b'] := LByID(dingo_RoleID);
              dingo_sl.Values['u_b'] := RByID(dingo_RoleID);
              AppServer.InsertDBRecord(SourceName, '', '457363,11011', False, dingo_sl);
              
              //
              DingoCopyLinks(dingo_UserIDs.Strings[0], dingo_RoleID, '308850,11011', '457360,11011', ftIDB);
              DingoCopyLinks(dingo_UserIDs.Strings[0], dingo_RoleID, '306945,11011', '457361,11011', ftIDB);
              DingoCopyLinks(dingo_UserIDs.Strings[0], dingo_RoleID, '306946,11011', '457362,11011', ftIDB);
            end;
        
        //
        dingo_UserIDs.Delete(0);
      end;
    
    // nacteni skladovych sektoru
    StringToSL(AppServer.GetDBKeyValues(SourceName, rmPrimary, '25152789,10', ''), ';', dingo_SectorIDs);
    while dingo_SectorIDs.Count > 0 do
      begin
        if not AppServer.ExistDBKeyValue(SourceName, rmPrimary, '457560,11011', dingo_SectorIDs.Strings[0], ftIDB) then
          if AppServer.GetDBKeyValues(SourceName, rmPrimary, '457355,11011', Format('"remotekey" = ''%%''', [dingo_SectorIDs.Strings[0]])) = '' then
            begin
              // tvorba role WMS
              dingo_sl.Clear;
              dingo_sl.Values['remotekey'] := dingo_SectorIDs.Strings[0];
              dingo_sl.Values['46136,10015'] := AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '17684,10', '1043023,10', dingo_SectorIDs.Strings[0]);
              dingo_sl.Values['236,1'] := Format('Sektor [%%]', [dingo_sl.Values['46136,10015']]);
              dingo_sl.Values['412554,10'] := dingo_sl.Values['46136,10015'];
              AppServer.InsertDBRecord(SourceName, MainLang, '457355,11011', False, dingo_sl);
              dingo_RoleID := Format('%%,%%', [dingo_sl.Values['ic'], dingo_sl.Values['u']]);
              
              // aktivni role WMS prihlasovaciho uctu
              dingo_sl.Clear;
              dingo_sl.Values['ic_a'] := LByID(dingo_RoleID);
              dingo_sl.Values['u_a'] := RByID(dingo_RoleID);
              dingo_sl.Values['ic_b'] := LByID(dingo_SectorIDs.Strings[0]);
              dingo_sl.Values['u_b'] := RByID(dingo_SectorIDs.Strings[0]);
              AppServer.InsertDBRecord(SourceName, '', '457560,11011', False, dingo_sl);
              
              DingoCopyLinks(dingo_SectorIDs.Strings[0], dingo_RoleID, '205697,11011', '457579,11011', ftIDB);
            end;
        
        //
        dingo_SectorIDs.Delete(0);
      end;
  finally
    dingo_SectorIDs.Free;
    dingo_UserIDs.Free;
    dingo_sl.Free;
  end;
  // Dingo - END
  
 
  
end.